#include "cpu/exec/template-start.h"

#define instr call

static void do_execute(int len, uint32_t address) {
	reg_l(R_ESP) -= 4;
    MEM_W(reg_l(R_ESP), cpu.eip + len + 1);
	print_asm("call\t0x%x", address + len + 1);
	cpu.eip = address;
}

make_helper(concat(call_i_, SUFFIX)) {
    int len = concat(decode_i_, SUFFIX)(cpu.eip + 1);
    uint32_t address = cpu.eip + op_src->val;
	do_execute(len, address);
	return 1 + len;
}

make_helper(concat(call_rm_, SUFFIX)) {
    int len = concat(decode_rm_, SUFFIX)(cpu.eip + 1);
    uint32_t address = op_src->val - len - 1;
	do_execute(len, address);
    return 1 + len;
}


#include "cpu/exec/template-end.h"